package com.wlstock.funi.adapter;

import android.content.Context;

import com.em.adapter.CommonAdapter;
import com.em.adapter.ViewHolder;
import com.wlstock.funi.R;
import com.wlstock.funi.dao.StrategyFundSelDao;
import com.wlstock.funi.model.MyAccountStocks;
import com.wlstock.funi.model.StrategyFundModel;

import java.util.List;

public class MyAccountStockAdapter extends CommonAdapter<MyAccountStocks> {

    public MyAccountStockAdapter(Context context, List<MyAccountStocks> datas, int layoutId) {
        super(context, datas, layoutId);
        this.mContext = context;
    }

    @Override
    public void convert(ViewHolder holder, MyAccountStocks stock) {
        holder.setText(R.id.tv_stk_info, stock.nameWithCode());
        holder.setText(R.id.tv_stk_qty, stock.getStkQty() + "");
        holder.setText(R.id.tv_cost_price, stock.getCostPrice());
        holder.setText(R.id.tv_cur_price, stock.curPrice());
        holder.setText(R.id.tv_profit, stock.curProfitStr() + stock.highProfitStr());
        holder.setText(R.id.tv_serverTradeTime, stock.serverTradeDate());
        holder.setText(R.id.tv_keepDays, stock.keepDateCountStr());

        StrategyFundModel straFundModel = StrategyFundSelDao.getInstance(mContext).queryStraModelWithCode(stock.getStkCode());
        if (straFundModel!=null){
            holder.setText(R.id.tv_target_keepdays, stock.getTargetDaysCountStr(straFundModel));
            holder.setText(R.id.tv_target_reason,stock.getBuyReason(straFundModel));
        }else{
            holder.setVisible(R.id.tv_target_keepdays, false);
            holder.setVisible(R.id.tv_target_reason, false);
        }

    }


}
